import { Component, OnInit } from '@angular/core';
import { UploadFile, NzMessageService } from 'ng-zorro-antd';
import { HttpClient, HttpRequest } from '@angular/common/http';
import { ResultList } from '../result-list';
import { RequestMapping } from '../request.mapping';

@Component({
  selector: 'app-user-upload-form',
  templateUrl: './user-upload-form.component.html',
  styleUrls: ['./user-upload-form.component.css']
})
export class UserUploadFormComponent implements OnInit {
  ngOnInit(): void {

  }
  uploading = false;
  fileList: UploadFile[] = [];

  constructor(private http: HttpClient, private msg: NzMessageService) { }

  beforeUpload = (file: UploadFile): boolean => {
    this.fileList.push(file);

    console.log(this.fileList.length)
    return false;
  }  

  handleUpload() {
    const formData = new FormData();
    this.fileList.forEach((file: any) => {
      formData.append('files', file);
    });
    this.uploading = true;
    // You can use any AJAX library you like
    this.http.post<ResultList>(RequestMapping.USER_EXCEL_UPLOAD, formData).toPromise()
    .then(response => {
      if(response.status == 200){
        this.msg.success("您上传的文件中所包含的用户信息已经全部保存成功",{nzDuration: 5000});
        
      }
    })





  }

}
